#include "VertexBuffer.h"
#include "Utility/Utility.h"

CVertexBuffer::CVertexBuffer( UINT32 dwID, ResourceHandle hHandle, EResourceType eResType, 
							  UINT32 dwVertexCount, UINT32 dwVertexSize )
	: CHardwareResource(dwID, hHandle, eResType)
	, m_dwVertexCount(dwVertexCount)
	, m_dwVertexSize(dwVertexSize)
{

}

CVertexBuffer::~CVertexBuffer()
{
}


void CVertexBuffer::Release()
{
	ID3D10Buffer* pD3DBuf  = (ID3D10Buffer*)m_hRealHandle;
	SAFE_RELEASE(pD3DBuf);

	CHardwareResource::Release();
}


ID3D10Buffer* CVertexBuffer::GetHandle()
{
	return static_cast<ID3D10Buffer*>(m_hRealHandle);
}

void* CVertexBuffer::Lock()
{
	void* pData = NULL;
	ID3D10Buffer* pD3DBuf  = (ID3D10Buffer*)m_hRealHandle;

	HR(pD3DBuf->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&pData));

	return pData;
}

void CVertexBuffer::UnLock()
{
	ID3D10Buffer* pD3DBuf  = (ID3D10Buffer*)m_hRealHandle;
	pD3DBuf->Unmap();
}
